defmodule Giom.Accounting.Stocktrans do
  use Ecto.Schema
  import Ecto.Changeset


  schema "stocktrans" do
    field :doc_no, :string
    field :price, :decimal
    field :price_vat, :decimal
    field :trans_date, :utc_datetime
    field :create_date, :utc_datetime
    field :edit_date, :utc_datetime
    field :vat, :decimal
    field :stock_code, :string
    field :source_code, :string
    field :target_code, :string
    field :m_unit,  :string,size: 2
    field :doc_type,  :string,size: 1
    field :comment,  :string
    field :row_no,  :integer
    field :qty, :decimal
    field :i_qty, :decimal,default: 0.0
    field :i_qty2, :decimal,default: 0.0
    field :i_qty3, :decimal,default: 0.0
    field :discount, :decimal,default: 0.0
    field :discount2, :decimal,default: 0.0
    field :discount3, :decimal,default: 0.0
    field :wbill_no, :string
	field :wbill_date, :utc_datetime
	field :track_code, :string
	field :track_code2, :string


    timestamps()
  end

  @doc false
  def changeset(stocktrans, attrs) do
    stocktrans
    |> cast(attrs, [:doc_no, :trans_date, :price, :price_vat, :vat])
    |> validate_required([:doc_no, :trans_date, :price, :price_vat, :vat])
    |> foreign_key_constraint(:stock_code)
    |> foreign_key_constraint(:source_code)
    |> foreign_key_constraint(:target_code)
    |> foreign_key_constraint(:doc_no)
  end
end
